#ifndef H_RCGD_TRACE_H
#define H_RCGD_TRACE_H

#define	TRACE_CONTROL_FIRST		0
#define	TRACE_CONTROL_SECOND	1
#define	TRACE_CONTROL_THIRD		2

#define TRACE_FIRST		0
#define TRACE_SECOND	1
#define TRACE_THIRD		2
#define TRACE_FOURTH	3
#define TRACE_FIFTH		4
#define TRACE_SIXTH		5
#define TRACE_SEVENTH	6
#define TRACE_EIGHTH	7


#define TRACKING_INTERVAL 	1


#define MAX_TraceDACTable_SIZE   100
#define MAX_TraceUTable_SIZE     5
#define TraceMonitorTable_SIZE   30


#define TRACE_CUTOFF		500*200


typedef struct TRACE_S{

	int 	ControlCounter;

	int 	DelayCounter;

	int 	DACTableDelayCounter;
	int 	DACTableIndex;
	double 	DACTable[MAX_TraceDACTable_SIZE];

	int 	UTableIndex;
	double 	UTable[MAX_TraceUTable_SIZE];
	double	MeanU;

	int 	MonitorTableIndex;
	int 	MonitorTable[TraceMonitorTable_SIZE];


	double 	AvgTimeOffset;
	double 	PrevAvgTimeOffset;
	double 	PrevU,CurrentU,NominalDAC;
	double 	MeanDAC;

	int 	detailSense;
	int		TimeOffset;
	int		PrevTimeOffset;
	int		TimeDifference;


	int		ReferenceADC;
	int		AverageADCValue;

	char EVENT;
	char TURN;
	int	IntervalCounter;
	int	ResyncCounter;

	char polarity;

	char	control_turn;

} TRACE_;



extern TRACE_	TRACE;

extern float PrevdDAC;


extern void InitializeTraceControl();
extern void TraceControl();
extern void Init_TRACE_Control();

extern void TraceControl_ExtRef();


extern int gTraceTableIndex;

extern int iTraceMatchCnt;
extern void funcReadTraceCounter();
extern void InitializeTraceControlSecond();

extern int debug_trace;
extern void Warmup_Trace_Control(void);

extern int warmup_trace_holdup;
extern double warmup_toffset;

void Start_Trace_Control();

#endif
